const mongoose = require('mongoose');

const DefaultDataAdapter = require('../default-report/default-data-adapter');
const ProjectVersion = require('../../../mongo/project-version');
const functions = require('../../../functions');

class DataAdapter extends DefaultDataAdapter {
  async getFunctionsOverview(versionId) {
    const version = await ProjectVersion.findOne({ _id: mongoose.Types.ObjectId(versionId) });
    const changed = version.oldVersionId ? ['added', 'modified'] : undefined;
    return functions.getOverview(versionId, { sortBy: ['fileId', 'index'], pageSize: 999999, changed })
      .then(([functionsOverview, , funcResultStatistic]) => [functionsOverview, funcResultStatistic]);
  }
}

module.exports = DataAdapter;
